package com.easthome.controller;

import com.easthome.common.RespResult;
import com.easthome.entity.Brands;
import com.easthome.entity.Goods;
import com.easthome.entity.GoodsType;
import com.easthome.pojo.form.GoodsPageConForm;
import com.easthome.pojo.vo.GoodTypeBrandVO;
import com.easthome.service.GoodsService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author cxiaoy
 * @Date 2022/10/19 9:12
 */
@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    @RequestMapping("/getGoodsList")
    public RespResult getGoodsList(){
        System.out.println("getGoodsList....");
        List<Goods> list = goodsService.getGoodsList();
        return RespResult.success(list);
    }

    @RequestMapping("/getGoodsTypeList")
    public RespResult getGoodsTypeList(HttpServletRequest req){
        System.out.println("getGoodsTypeList....");
        List<GoodsType> gtList = (List<GoodsType>)req.getServletContext().getAttribute("goodsTypeList");
        List<Brands> brandList = (List<Brands>)req.getServletContext().getAttribute("brandsList");
        return RespResult.success(new GoodTypeBrandVO(gtList,brandList));
    }

    @RequestMapping("/getGoodsListPage/{pageNum}")
    public RespResult getGoodsListPage(@PathVariable Integer pageNum){
        System.out.println("getGoodsListPage..."+pageNum);
        PageInfo pageInfo = goodsService.getGoodsListPage(pageNum);//本次查询结果为：分好的第n页中的数据,还有count，pageSize,pageNum等周边
        return RespResult.success(pageInfo);//res.data.data
    }

    @RequestMapping("/getGoodsListPageCon/{pageNum}")
    public RespResult getGoodsListPage(@PathVariable Integer pageNum,@RequestBody GoodsPageConForm goodsPageConForm){
        System.out.println("getGoodsListPageCon..."+goodsPageConForm+","+pageNum);
        PageInfo pageInfo = goodsService.getGoodsListPageCon(pageNum,goodsPageConForm);//本次查询结果为：分好的第n页中的数据,还有count，pageSize,pageNum等周边
        return RespResult.success(pageInfo);//res.data.data
    }

}
